package com.zhu.pre.controller;

import com.sanploy.common.domain.User;
import com.sanploy.common.vo.BaseException;
import com.zhu.pre.service.MUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by zhu yingzhi on 2017/9/21.
 * @author yingzhi zhu
 * 手机用户请求路由
 */
@RestController
@RequestMapping("/m/user")
public class MUserController {

    @Autowired
    private MUserService userService;

    //
//
    @GetMapping("logout")
    public Object getUsers(@RequestParam String token){
        return userService.logout(token);
    }

    /**
     * 登录接口
     * @param code
     * @param session
     * @return
     * @throws IOException
     * @throws BaseException
     */
    @PostMapping("/login")
    public Object login(@RequestParam String code, @RequestParam String token,HttpSession session) throws IOException, BaseException {
        return userService.login(code, token);
    }

    /**
     * 注册接口
     * @param user  实体对象 自动注入
     * @param nickName 昵称
     * @param avatarUrl 头像
     * @param gender 性别
     * @param province 省
     * @param city 市
     * @param country 国家
     * @throws IOException
     * @throws BaseException
     */
    @PostMapping("/register")
    public Object register(User user,HttpSession session,@RequestParam String token,@RequestParam String nickName,@RequestParam String avatarUrl,
                           @RequestParam String gender,@RequestParam String province,@RequestParam String city,
                           @RequestParam String country) throws IOException, BaseException {
        return userService.register(token, user);
    }




}
